package com.scrum.Connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnection {
	public static Connection conn = null;
	public static Statement stt = null;
	public static ResultSet result = null;

	public static Connection connectDB() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/travelholic", "root", "");

		} catch (Exception ex) {
			System.out.println("Error Database");
			System.out.println(ex.getMessage());
		}

		return conn;
	}

	public static ResultSet getData(String sql) {
		if (conn == null) {
			conn = connectDB();
		}
		try {
			stt = conn.createStatement();
			result = stt.executeQuery(sql);
		} catch (Exception e) {
			System.out.println("Loi getdata");
			e.printStackTrace();
		}
		return result;
	}
	public static void closeConnection(){
		try {
			stt.close();
			result.close();
		} catch (Exception e) {
			System.out.println("Err Close connection");
		}
		
	}
}
